package org.cupk2.wdap.convertor.impl;

import org.cupk2.files.domain.ResourceFile;
import org.cupk2.files.service.ResourceFileServiceInter;
import org.cupk2.tools.files.Cupk2FileUtils;
import org.cupk2.tools.files.Cupk2ProcessState;
import org.cupk2.wdap.convertor.filemode.impl.PdfFileMode;
import org.cupk2.wdap.convertor.filemode.impl.ResourceFileMode;
import org.cupk2.wdap.convertor.filemode.inter.FileModel;
import org.cupk2.wdap.convertor.inter.FileConvertorInter;
import org.cupk2.wdap.convertor.utils.ConvertResult;
import org.cupk2.wdap.convertor.utils.ConvertUtils;
import org.cupk2.wdap.convertor.utils.ConvertorParam;
import org.cupk2.wdap.domain.WdapConvertor;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class PdfConvertor implements FileConvertorInter {

    static {

        ConvertUtils.registImpl((new PdfConvertor()).getClass());
    }

    @Override
    public List<ConvertorParam> getParams() {
        List<ConvertorParam> paras = new ArrayList<>();
        return paras;
    }

    @Override
    public String getTitle() {
        return "PDF复制预览";
    }

    @Override
    public String getNote() {
        return "PDF复制到PDF预览文件";
    }

    @Override
    public ConvertResult runConvert(ResourceFile resourcefile, FileModel filemodel, WdapConvertor convertor, Map<String, ConvertorParam> params, Map<String, Object> flowContext, ResourceFileServiceInter resourceFileServiceImpl) {
        File file = filemodel.getFile(resourcefile, resourceFileServiceImpl);
        PdfFileMode pdfFileMode = new PdfFileMode();

        File pdffile = pdfFileMode.getFile(resourcefile, resourceFileServiceImpl);
        Cupk2FileUtils.copyTo(file, pdffile, new Cupk2ProcessState());

        ConvertResult result = new ConvertResult(true);
        result.addFileModel(pdfFileMode.getKey());
        return result;
    }


    @Override
    public List<FileModel> getSourceFileModel() {
        List<FileModel> list = new ArrayList<>();
        list.add(new ResourceFileMode());
        return list;
    }

    @Override
    public FileModel getTargetFileModel() {
        return new PdfFileMode();
    }

    @Override
    public void valideParams(List<ConvertorParam> params) {
    }
}
